<?php

if (isset($_POST['act']))
{
	if ($_POST['act'] == "edit_mod")
	{
		$get_result = edit_mod(@$_POST['name_a'], @$_POST['link_a'], @$_POST['show_a'], @$_POST['name_l'], @$_POST['link_l'], @$_POST['show_l'], @$_POST['actif'], @$_POST['actif2'], @$_POST['mid']);
		if ($get_result == 0)
		{
			$div = "valid";
			$msg = "Les modifications ont bien &eacute;t&eacute; enregistr&eacute;es!";
		}	
		elseif ($get_result == -1)
		{
			$div = "error";
			$msg = "Vous n'avez pas le droit de modifier ce module!";
		}
		else
		{
			$div = "error";
			$msg = "Erreur lors de la modification du module!";
		}
	}
	elseif ($_POST['act'] == "delete_mod")
	{
		$get_result = delete_mod(@$_POST['mid'], @$_POST['type']);
		if ($get_result == 0)
		{
			$div = "valid";
			$msg = "Le module a bien &eacute;t&eacute; supprim&eacute;!";
		}
		elseif ($get_result == -1)
		{
			$div = "error";
			$msg = "Vous n'avez pas le droit de supprimer ce module!";
		}
		elseif ($get_result == -2)
		{
			$div = "error";
			$msg = "Impossible de supprimer le module! D'autres applications d&eacute;pendent de lui!";
		}
		elseif ($get_result == -3)
		{
			$div = "error";
			$msg = "Erreur, impossible de supprimer le module!";
		}
	}
	elseif ($_POST['act'] == "rights_mod")
	{
		if ($_POST['type'] == "deluid")
			$get_result = set_rights_mod(@$_POST['mid'], @$_POST['users'],"uid", "rm");
		elseif ($_POST['type'] == "delgid")
			$get_result = set_rights_mod(@$_POST['mid'], @$_POST['groups'],"gid", "rm");
		elseif ($_POST['type'] == "adduid")
			$get_result = set_rights_mod(@$_POST['mid'], @$_POST['users'],"uid", "mk");
		elseif ($_POST['type'] == "addgid")
			$get_result = set_rights_mod(@$_POST['mid'], @$_POST['groups'],"gid", "mk");
			
		if ($get_result == 0)
		{
			$div = "valid";
			$msg = "Les droits ont bien &eacute;t&eacute; modfi&eacute;s!";
		}
		elseif ($get_result == -1)
		{
			$div = "error";
			$msg = "Impossible de modifier les droits!";
		}
	}
	elseif ($_POST['act'] == "link_add")
	{
		
		$get_result = add_link(@$_POST['title'], @$_POST['link']);
		if ($get_result == 0)
		{
			$div = "valid";
			$msg = "Le lien a bien &eacute;t&eacute; enregistr&eacute;!";
		}
		else
		{
			$div = "error";
			$msg = "Erreur lors de l'ajout du lien!";
		}
	}
	Print("
		<div id=\"$div\" style=\"visibility: visible;\">
			$msg
		</div>
		<br>
	");
}
elseif (isset($_GET['gr']))
{
	$get_result = $_GET['gr'];
	if ($get_result == 0)
	{
		$div = "valid";
		$msg = "Le module a bien &eacute;t&eacute; install&eacute!";
	}
	elseif ($get_result == -1)
	{
		$div = "error";
		$msg = "Vous n'avez pas le droit d'installer de modules!";
	}
	elseif ($get_result == -2)
	{
		$div = "error";
		$msg = "Le module est d&eacute;j&agrave; install&eacute;!";
	}
	elseif ($get_result == -3)
	{
		$div = "error";
		$msg = "Erreur dans le fichier de configuration!";
	}
	elseif ($get_result == -4)
	{
		$div = "error";
		$msg = "Erreur lors de l'installation!";
	}
	elseif ($get_result == -5)
	{
		$div = "error";
		$msg = "Ce module n&eacute;cessite l'installation d'un autre module!";
	}
	Print("
		<div id=\"$div\" style=\"visibility: visible;\">
			$msg
		</div>
		<br>
	");
}

if (@$_GET['st'] == "")
	$st = 0;
else
	$st = $_GET['st'];

Print("
	<div id=\"box\">
		<h3>Modules</h3>
		<div style=\"border:1px gray dotted; height:275px;\">
		<table width=100% cellpading=0 cellspacing=0 border=0 class=\"tab_over_1\">
			<thead>
				<tr>
					<th width=5% align=left><font color=royalblue>ID</font></th>
					<th width=20% align=left><font color=royalblue>Module</font></th>
					<th width=40% align=left><font color=royalblue>Description</font></th>
					<th width=9% align=left><font color=royalblue>Type</font></th>
					<th width=5% align=left><font color=royalblue>Version</font></th>
					<th width=5% align=center><font color=royalblue>Status</font></th>
					<th width=15% align=center><font color=royalblue>Actions</font></th>
				</tr>
			</thead>");
				show_modules($st, 9);
		Print("</table>
		</div>");
			show_page($st, 9, $_SESSION['prefix']."modules", "mid", "modules.php?st");
	Print("</div>
	
	<br><br>
	
	<div id=\"box\">
		<h3>Nouveaux modules</h3>
		<div style=\"border:1px gray dotted; height:275px;\">
		<table width=100% cellpading=0 cellspacing=0 border=0 class=\"tab_over_1\">
			<thead>
				<tr>
					<th width=25% align=left><font color=royalblue>Module</font></th>
					<th width=50% align=left><font color=royalblue>Description</font></th>
					<th width=5% align=left><font color=royalblue>Version</font></th>
					<th width=10% align=center><font color=royalblue>Actions</font></th>
				</tr>
			</thead>");
				show_new_modules();
		Print("</table>
		</div>
	</div>");
	
?>